home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / TESTPRGS / graphics / TextView_test.cxx < prev   
Encoding:
C/C++ Source or Header  |  1994-08-29  |  6.4 KB  |  237 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:RCS/testprgs/graphics/TextView_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *    $Revision: 1.7 $
  9.  *    $Date: 1994/07/23 19:15:03 $
  10.  *    $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. extern "C" {
  16. #include <dos/dos.h>
  17. #include <stdio.h>
  18. }
  19.  
  20. #include <APlusPlus/exec/SignalResponder.h>
  21. #include <APlusPlus/intuition/GWindow.h>
  22. #include <APlusPlus/gadtools/GT_Scroller.h>
  23. #include <APlusPlus/intuition/BoopsiGadget.h>
  24. #include <APlusPlus/graphics/TextView.h>
  25. #include <APlusPlus/intuition/IntuiMessageC.h>
  26. #include <APlusPlus/graphics/GBorder.h>
  27. #include <iostream.h>
  28.  
  29. static const char rcs_id[] = "$Id: TextView_test.cxx,v 1.7 1994/07/23 19:15:03 Armin_Vogt Exp Armin_Vogt $";
  30.  
  31.  
  32. BOOL running = TRUE;
  33. BOOL close2 = FALSE;
  34.  
  35. class MySRSP : public SignalResponder
  36. {
  37.    public:
  38.       MySRSP(BYTE signal) : SignalResponder(signal,0) {}
  39.       ~MySRSP() {}
  40.       // overload the virtual 'signal received' action callback method.
  41.       void actionCallback()
  42.       {
  43.          cout << "**Break\n";
  44.          running = FALSE;
  45.       }
  46. };
  47. class MyTv : public TextView
  48. {
  49.    public:
  50.       MyTv(GOB_OWNER,AttrList& attrs) : TextView(gob_owner,attrs) { }
  51.       ~MyTv() {}
  52.       
  53.       // runtime type inquiry support
  54.       static const Intui_Type_info info_obj;
  55.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  56.          { return info_obj; }
  57.       static const Type_info& info()                // get the 'type_id' of a specific class
  58.          { return info_obj; }
  59.  
  60.    protected:
  61.       UBYTE *getLineString(LONG line,UWORD& len)
  62.       {
  63.          static UBYTE string[60];
  64.          sprintf((char*)&string[0],"This is line %3ld of a text displayed in a TextView in Times 15p.",line);
  65.          len = strlen((char*)string);
  66.          return string;
  67.       }
  68.       void formatOutput(UBYTE *lineText,UWORD length)
  69.       {
  70.          if (length>17)
  71.          {
  72.             setDrMd(JAM1);
  73.             setAPen(1);
  74.             text(lineText,8);
  75.             setAPen(3);
  76.             text(lineText+8,9);
  77.             setAPen(1);
  78.             text(lineText+8+9,length-8-9);
  79.          }
  80.       }
  81.       void callback(const IntuiMessageC *imsg)
  82.       {
  83.          TextView::callback(imsg);
  84.  
  85.       }
  86.  
  87. };
  88.  
  89. intui_typeinfo(MyTv, derived(from(TextView)), rcs_id)
  90.  
  91.  
  92. /******************************************************************************
  93.  
  94.       MyWindow class is a window containing a TextView with two scrollers
  95.       attached to
  96.  
  97.  ******************************************************************************/
  98. class MyWindow : public GWindow
  99. {
  100.    public:
  101.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs) { init(); }
  102.  
  103.       void On_CLOSEWINDOW(const IntuiMessageC *msg)
  104.       {
  105.          cout << "CLOSEWINDOW.\n";
  106.          delete this;
  107.          running = FALSE;
  108.       }
  109.       void On_ACTIVEWINDOW(const IntuiMessageC *msg)
  110.       {
  111.          cout << title() << " is ACTIVE.\n";
  112.       }
  113.       void On_SIZEVERIFY(const IntuiMessageC *msg)
  114.       {
  115.          cout << "SIZEVERIFY. \n";
  116.       }
  117.       void handleIntuiMsg(const IntuiMessageC* imsg)
  118.       {
  119.          switch (imsg->getClass())
  120.          {
  121.             case CLASS_CLOSEWINDOW :
  122.                On_CLOSEWINDOW(imsg); break;
  123.             case CLASS_ACTIVEWINDOW :
  124.                On_ACTIVEWINDOW(imsg); break;
  125.             case CLASS_SIZEVERIFY :
  126.                On_SIZEVERIFY(imsg); break;
  127.          }
  128.          GWindow::handleIntuiMsg(imsg);
  129.       }
  130.             
  131.       // runtime type inquiry support
  132.       static const Intui_Type_info info_obj;
  133.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  134.          { return info_obj; }
  135.       static const Type_info& info()                // get the 'type_id' of a specific class
  136.          { return info_obj; }
  137.  
  138.    private:
  139.       void init();
  140.       BevelBox bevel;
  141. };
  142.  
  143. intui_typeinfo(MyWindow, derived(from(GWindow)), rcs_id);
  144.  
  145.  
  146. void MyWindow::init()
  147. {
  148.    modifyIDCMP(CLASS_NEWSIZE|CLASS_CLOSEWINDOW|CLASS_ACTIVEWINDOW|CLASS_SIZEVERIFY \
  149.    |CLASS_GADGETDOWN|CLASS_GADGETUP|CLASS_MOUSEMOVE|CLASS_RAWKEY|CLASS_VANILLAKEY);
  150.  
  151.    MyTv *myTextView = new MyTv(this, AttrList(
  152.       GOB_LeftFromLeftOfParent,0,
  153.       GOB_TopFromTopOfParent,0,
  154.       GOB_RightFromRightOfParent,-18,
  155.       GOB_BottomFromBottomOfParent,-18,
  156.       GOB_BorderObj(&bevel),
  157.       CNV_Width, 1000,
  158.       CNV_GranularityX, 30,
  159.       TXV_Lines, 50,
  160.       TXV_FontName, "times.font",
  161.       TXV_FontSize, 15,
  162.       TXV_CursorOn, TRUE,
  163.       TAG_END) );
  164.  
  165.    BoopsiGadget *boopsiG = new BoopsiGadget(this,
  166.       (UBYTE*)"propgclass", AttrList(
  167.       GOB_LeftFromRightOfPred,2,
  168.       GOB_TopFromTopOfParent,0,
  169.       GOB_RightFromRightOfParent,0,
  170.       GOB_BottomFromBottomOfPred,0,
  171.       GOB_BorderObj(&bevel),
  172.       GA_Immediate,TRUE,
  173.       GA_RelVerify,TRUE,
  174.       PGA_Freedom,FREEVERT,
  175.       ICA_TARGET,ICTARGET_IDCMP,
  176.       PGA_NewLook,TRUE,
  177.       CONSTRAINT(PGA_Top,myTextView,CNV_ViewY),
  178.       CONSTRAINT(PGA_Visible,myTextView,CNV_VisibleY),
  179.       CONSTRAINT(PGA_Total,myTextView,CNV_Height),
  180.       TAG_END) );
  181.  
  182.    GT_Scroller *gtscG = new GT_Scroller(this,
  183.    AttrList(   GOB_LeftFromLeftOfParent,0,
  184.       GOB_TopFromBottomOfPred,2,
  185.       GOB_RightFromLeftOfPred,0,
  186.       GOB_BottomFromBottomOfParent,0,
  187.       GA_Immediate,TRUE,
  188.       GA_RelVerify,TRUE,
  189.       PGA_Freedom,LORIENT_HORIZ,
  190.       GTSC_Arrows,16,
  191.       CONSTRAINT(GTSC_Top,myTextView,CNV_ViewX),
  192.       CONSTRAINT(GTSC_Visible,myTextView,CNV_VisibleX),
  193.       CONSTRAINT(GTSC_Total,myTextView,CNV_Width),
  194.       TAG_END) );
  195.  
  196.    myTextView->setAttributes( AttrList(
  197.       CONSTRAINT(CNV_ViewX,gtscG,GTSC_Top),
  198.       CONSTRAINT(CNV_ViewY,boopsiG,PGA_Top),
  199.       TAG_END) );
  200.  
  201.    refreshGList();   // display the gadgets
  202.  
  203. }
  204.  
  205.  
  206. void APPmain(int argc,char* argv[])
  207. {
  208.    MySRSP sr(SIGBREAKB_CTRL_C);
  209.       LineBorder lineBorder;
  210.  
  211.    new MyWindow(OWNER_NULL,
  212.    AttrList(   WA_Title,"WindowC - close this to stop.",
  213.       WA_Width,300,
  214.       WA_Height,150,
  215.       WA_MinWidth,200,
  216.       WA_MinHeight,100,
  217.       WA_MaxHeight,1600,
  218.       WA_MaxWidth,1600,
  219.       WA_DragBar,TRUE,
  220.       WA_SizeGadget,TRUE,
  221.       WA_DepthGadget,TRUE,
  222.       WA_CloseGadget,TRUE,
  223.       WA_IDCMP,IDCMP_CLOSEWINDOW,
  224.       WA_SmartRefresh,TRUE,
  225.       GOB_BorderObj(&lineBorder),
  226.       TAG_END) );
  227.  
  228.  
  229.  
  230.    while (running)
  231.    {
  232.       SignalResponder::WaitSignal();
  233.    }
  234.  
  235.    cout << "main() end.\n";
  236. }
  237.